<script type="text/javascript">
/**
 * ------------------------------------------------------
 * 操作权限管理页面
 * ------------------------------------------------------
 */
$(function(){
	$("#operation_edit_submit").button().click(function(){
		var group_id=$("#operation_edit_group select").val();
		var add="";
		$(".operation_add input[type='radio']").each(function(){
			if($(this).is(":checked")){
				add+=$(this).val();
			}
		})
		if(add==""){
			artError("请设置新增权限");
			return;
		}
		var del="";
		$(".operation_del input[type='radio']").each(function(){
			if($(this).is(":checked")){
				del+=$(this).val();
			}
		})
		if(del==""){
			artError("请设置删除权限");
			return;
		}
		var edit="";
		$(".operation_edit input[type='radio']").each(function(){
			if($(this).is(":checked")){
				edit+=$(this).val();
			}
		})
		if(edit==""){
			artError("请设置修改权限");
			return;
		}
		$("#operation_edit_submit").button("disable");
		$.post(BASE+"/admin/manage/operation",{"group_id":group_id,"add":add,"edit":edit,"del":del},
			function(e){
				if(e.status==1){
					artSuccess(e.info);
				}else{
					artError(e.info);
				}
				$("#operation_edit_submit").button("enable");
			}
		,"json");
	});
	
	$("input[name='operation_all']").click(function(){
		var check=$(this).val();
		$("#operation_edit_table input[type='radio'][value='"+check+"']").each(function(){
			$(this).attr("checked",true);
		});
	});
	
	checkRadioAll("add");
	checkRadioAll("del");
	checkRadioAll("edit");
	function checkRadioAll(type,val){
		$("input[name='operation_"+type+"_all']").click(function(){
			var check=$(this).val();
			$(".operation_"+type).find("input[type='radio'][value="+check+"]").each(function(){
				$(this).attr("checked",true);
			})
		})
	}
	
	radioChange($("#operation_edit_group select").val());
	$("#operation_edit_group select").change(function(){
		radioChange($(this).val());
	});
	
	function radioChange(group_id){
		$.post(BASE+"/admin/manage/operation",{"oper":"get_operation","group_id":group_id},function(e){
			if(!isEmpty(e)){
				$.each(e,function(i,n){
					$(".operation_add input[name='operation_add_"+i+"'][value='"+n.add+"']").attr("checked",true);
					$(".operation_edit input[name='operation_edit_"+i+"'][value='"+n.edit+"']").attr("checked",true);
					$(".operation_del input[name='operation_del_"+i+"'][value='"+n.del+"']").attr("checked",true);
				});
			}else{
				//默认拥有所有权限
				$("#operation_edit_group input[type=radio][value=1]").attr("checked",true);
			}
		},"json");
	}
})

</script>
<div id="show_operation_edit" class="main">
	<div class="main_left">
	<form name="operation" method="post">
		<notempty name="group">
		<div class="title_container">
			<label id="operation_edit_group">
				<span class="title_label">{$Think.lang.SELECT_GROUP}</span>
				<span>
					<select name="group_id">
						<foreach name="group" key="group_id" item="g">
						<option value="{$group_id}">{$g["name"]}</option>
						</foreach>
					</select>
				</span>
			</label>
			<span id="operation_edit_all">
				<b>{$Think.lang.SELECT_ALL}</b>
				<label><input type="radio" name="operation_all" value="1"/><b>{$Think.lang.YES}</b></label>
				&nbsp;
				<label><input type="radio" name="operation_all" value="0"/><b>{$Think.lang.NO}</b></label>
			</span>
		</div>
		<else/>
		<div class="tip">{$Think.lang.SET_GROUP}</div>
		</notempty>
		<div class="common_table_holder">
			<table cellspacing="0" id="operation_edit_table">
				<tr>
					<th class="common_first_col" width="150">{$Think.lang.MENU_OPERATION}</th>
					<th>{$Think.lang.ADD_OPERATION}</th>
					<th>{$Think.lang.DEL_OPERATION}</th>
					<th>{$Think.lang.EDIT_OPERATION}</th>
				</tr>
				<tr>
					<td class="common_first_col">&nbsp;&nbsp;&nbsp;<b>{$Think.lang.SET_ALL_OPERATION}</b></td>
					<td align="center"><label><input type="radio" name="operation_add_all" value="1"/><b>{$Think.lang.YES}</b></label><label><input type="radio" name="operation_add_all" value="0"/><b>{$Think.lang.NO}</b></label></td>
					<td align="center"><label><input type="radio" name="operation_del_all" value="1"/><b>{$Think.lang.YES}</b></label><label><input type="radio" name="operation_del_all" value="0"/><b>{$Think.lang.NO}</b></label></td>
					<td align="center"><label><input type="radio" name="operation_edit_all" value="1"/><b>{$Think.lang.YES}</b></label><label><input type="radio" name="operation_edit_all" value="0"/><b>{$Think.lang.NO}</b></label></td>
				</tr>
				<foreach name="items" key="i" item="item">
					<tr>
						<td class="common_first_col">&nbsp;&bull;&nbsp;{$item.name}</td>	
						<td align="center" class="operation_add"><label><input type="radio" name="operation_add_{$i}" value="1"/>{$Think.lang.YES}</label><label><input type="radio" name="operation_add_{$i}" value="0"/>{$Think.lang.NO}</label></td>
						<td align="center" class="operation_del"><label><input type="radio" name="operation_del_{$i}" value="1"/>{$Think.lang.YES}</label><label><input type="radio" name="operation_del_{$i}" value="0"/>{$Think.lang.NO}</label></td>
						<td align="center" class="operation_edit"><label><input type="radio" name="operation_edit_{$i}" value="1"/>{$Think.lang.YES}</label><label><input type="radio" name="operation_edit_{$i}" value="0"/>{$Think.lang.NO}</label></td>
					</tr>
				</foreach>
			</table>
			<notempty name="group">
			<span><input type="button" value="{$Think.lang.OK}" id="operation_edit_submit" /></span>
			<span id="operation_edit_status"></span>
			</notempty>	
		</div>	
	</form>
	</div>
	<div class="main_right">
		{$Think.lang.TIP_H3}
		{$Think.lang.OPERATION_TIP}
	</div>
</div>